<template>
    <div>
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item',item.id == 0 ? 'mui-active' : '']" @click="getListImg(item.id)" v-for="item in classList" :key="item.id" data-wid="tab-top-subpage-1.html">
                        {{item.title}}
                    </a>
                </div>
            </div>
        </div>
        <ul class="photo-list">
            <router-link :to="'/home/photoinfo/' + item.id" tag="li" v-for="item in list" :key="item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <h1 class="info-title">{{item.title}}</h1>
                    <div class="info-body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>
<script type="text/ecmascript-6">
    //导入mui的js文件
    import mui from  "../../lib/mui/js/mui.js"
    export default{
        data(){
            return {
                classList: [], //所有分类的列表
                list: [] //图片列表的数组
            }
        },
        created(){
            this.getAllClassification();
//            默认进入页面，就主动请求所有图片列表的数据
            this.getListImg(0);
        },
        mounted(){
//            初始化滑动控件
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods: {
//            获取所有分类
            getAllClassification(){
                this.$http.get("photolist/photolist.json").then(result => {
                    if(result.body.status === 0){
                        result.body.message.unshift({
                            title: "全部",
                            id: 0
                        });
                        this.classList = result.body.message;
                    }
                })
            },
            getListImg(id){
//                根据分类id获取图片列表
                this.$http.get("photoimg/photoimg-" + id + ".json").then(result => {
                    if(result.body.status === 0){
                        this.list = result.body.message;
                    }
                });
            }
        }
    }
</script>
<style lang="less" scoped>
    *{
        touch-action: pan-y;
    }

    .photo-list{
        margin: 0;
        padding: 10px;
        padding-bottom: 0;
        list-style: none;
        li{
            background-color: #ccc;
            text-align:center;
            margin-bottom: 10px;
            box-shadow: 0 0 9px #999;
            position: relative;
            img[lazy=loading] {
                width: 40px;
                height: 300px;
                margin: auto;
            }
            img{
                width: 100%;
                vertical-align: top;
            }
            .info{
                position: absolute;
                bottom: 0;
                left: 0;
                max-height: 84px;
                color: white;
                text-align: left;
                background-color: rgba(0,0,0,.4);
                .info-title{
                    font-size: 14px;
                }
                .info-body{
                    font-size: 13px;
                }
            }
        }
    }
    /**
    *这是Chrome为了提高页面的滑动流畅度而弄出来的新东西
    * touch-action用于指定某个特定的区域是否允许用户操作，以及如何响应用户操作(如浏览器自带的滑动、缩放等)
    */
    /**
    *解决tabbar点击无法切换的问题
    */
</style>